package com.luo.chengrui.module.crbpm.service.flowable;

import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import com.luo.chengrui.module.crbpm.controller.admin.flowable.vo.*;
import com.luo.chengrui.module.crbpm.dal.dataobject.flowable.ActReModelDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;

import com.luo.chengrui.module.crbpm.convert.flowable.ActReModelConvert;
import com.luo.chengrui.module.crbpm.dal.mysql.flowable.ActReModelMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.luo.chengrui.module.crbpm.enums.ErrorCodeConstants.*;

/**
 * 流程模型 Service 实现类
 *
 * @author luodz
 */
@Service
@Validated
public class ActReModelServiceImpl implements ActReModelService {

    @Resource
    private ActReModelMapper actReModelMapper;

    @Override
    public void updateActReModel(ActReModelUpdateReqVO updateReqVO) {
        // 更新
        ActReModelDO updateObj = ActReModelConvert.INSTANCE.convert(updateReqVO);
        actReModelMapper.updateById(updateObj);
    }


    private void validateActReModelExists(String id, SFunction<ActReModelDO, ?> field, Object value, final ErrorCode errorCode) {
        ActReModelDO entity = actReModelMapper.selectOne(field, value);
        if (entity == null) {
            return;
        }
        if (id == null || !Objects.equals(entity.getId(), id)) {
            throw exception(errorCode);
        }
    }

    @Override
    public ActReModelDO getActReModel(String id) {
        return actReModelMapper.selectById(id);
    }

    @Override
    public List<ActReModelDO> getActReModelList(Collection<String> ids) {
        return actReModelMapper.selectBatchIds2(ids);
    }

    @Override
    public PageResult<ActReModelDO> getActReModelPage(ActReModelPageReqVO pageReqVO) {
        return actReModelMapper.selectPage(pageReqVO);
    }

    @Override
    public List<ActReModelDO> getActReModelList(ActReModelExportReqVO exportReqVO) {
        return actReModelMapper.selectList(exportReqVO);
    }

}
